package org.bbb.library1.views;

/*******************************************************************************
 * Copyright (c) 2007 Finalist IT Group B.V.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Rob Schellhorn - initial API and implementation
 *******************************************************************************/
//package com.finalist.rcp.internal.view;

import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.part.ViewPart;

//import org.bbb.library1.ExplorerContentProvider;
//import org.bbb.library1.ExplorerLabelProvider;
import org.bbb.library1.RcpDemoPlugin;

/**
 * @author Rob Schellhorn
 */
public class Explorer extends ViewPart {

   public static final String VIEW_ID = "org.bbb.library1.views.explorer";

   private TreeViewer viewer;

   /*
    * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
    */
   @Override
   public void createPartControl(Composite parent) {
      viewer = new TreeViewer(parent);
      viewer.setComparator(new ViewerComparator());
      viewer.setContentProvider(new ExplorerContentProvider());
      viewer.setLabelProvider(new ExplorerLabelProvider());
      viewer.setInput(RcpDemoPlugin.getDefault().getLibrary());

      MenuManager popup = new MenuManager();
      popup.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));

      Tree tree = viewer.getTree();
      Menu menu = popup.createContextMenu(tree);
      tree.setMenu(menu);

      IWorkbenchPartSite site = getSite();
      site.registerContextMenu(popup, viewer);
      site.setSelectionProvider(viewer);
   }

   /*
    * @see org.eclipse.ui.part.WorkbenchPart#dispose()
    */
   @Override
   public void dispose() {
      try {
         viewer.getTree().dispose();
      } finally {
         super.dispose();
      }
   }

   /*
    * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
    */
   @Override
   public void setFocus() {
      viewer.getTree().setFocus();
   }
}




